package com.tony.mulitithread.utils;

import lombok.extern.log4j.Log4j2;

import java.lang.reflect.Method;

@Log4j2
public class ReflectionUtil {
    /**
     * @param object 服务对象
     * @param methodName 方法名称
     * @param args 参数
     * @throws Exception
     */
    public static void invokeMethod(Object object, String methodName, Object[] args) throws Exception{
        log.warn("invokeMethod start : 服务对象={},调用方法={}",new Object[]{object,methodName} );
        Class<?>[] paramClasses = null;
        if (args.length > 0){
            paramClasses = new Class<?>[args.length];
            for (int i = 0; i < args.length; i++) {
                paramClasses[i] = args[i].getClass();
            }
        }
        Method method = object.getClass().getMethod(methodName, paramClasses);
        method.setAccessible(true);
        method.invoke(object,args);
        log.warn("invokeMethod end ");
    }
}
